<?php
//
//	file: installer/inc_advnot.php
//	begin: 08/05/2007
//	$Author: christopher $
//	$Revision: 27 $
//	$Date: 2008-01-28 22:20:14 +0000 (Mon, 28 Jan 2008) $
//	license: http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)

if ( !defined('IN_PHPBB') || !defined('IN_INSTALL') )
{
	die('Hack attempt !');
	exit;
}

class advnot_install
{
	function advnot_install()
	{
		global $parms_def;

		// includes
		include($config->url('includes/aucp/class_advnot'));
		lang_include('lang_CH_install_advnot');

		// parms (not set is : type => TYPE_INT, default => 0)
		$parms_def += array(
			'nopv' => array('type' => TYPE_NO_HTML, 'default' => ''),
			'nond' => array('type' => TYPE_INT, 'default' => 0),
			'nomd' => array('type' => TYPE_INT, 'default' => 0),
		);

		return;
	}

	function start()
	{
		global $part_script, $page;

		// parms (not set is : type => TYPE_INT, default => 0)
		$part_script[] = sprintf($page->lang('NO_welcome_explain'), NOTIFY_CURRENT_VERSION);

		return;
	}

	function prev_vers()
	{
		global $db, $page, $parms;

		// check
		$parms['nopv'] = '';

		// aucp line
		$sql = 'SELECT config_value
					FROM ' . CONFIG_TABLE . '
					WHERE config_name = \'mod_aucp_notify\'';
		$result = $db->sql_query($sql, false, __LINE__, __FILE__);
		if ( $row = $db->sql_fetchrow($result) )
		{
			$parms['nopv'] = $row['config_value'];
		}
		$db->sql_freeresult($result);

		// standalone ch line
		if ($parms['nopv'] == '')
		{
			$sql = 'SELECT config_value
					FROM ' . CONFIG_TABLE . '
					WHERE config_name = \'mod_custom_title\'';
			$result = $db->sql_query($sql, false, __LINE__, __FILE__);
			if ( $row = $db->sql_fetchrow($result) )
			{
				$parms['nopv'] = $row['config_value'];
			}
			$db->sql_freeresult($result);
		}

		if ($parms['nopv'])
		{
			$page->output(sprintf($page->lang('NO_previous_version',$parms['nopv'])));
		}

		return;
	}
	function db()
	{
		global $parms;

		$parms['nond'] = $parms['nomd'] = false;

		// install schema
		switch ( $parms['nopv'] )
		{
			case '1.0.0':
				break;
			default:
				$schemas[] = 'advnot_ch';
				$parms['nond'] = true;
				break;
		}
		return;
	}

/*
	function migrate()
	{
		global $page, $db, $config, $parms;

		if (!$parms['nomd'])
		{
			return;
		}

		$page->output('NO_migrate_succeed');

		return;
	}
*/

	function init_data()
	{
		global $db, $page, $parms, $config;

		if ( !$parms['nond'] )
		{
			return;
		}

		return;
	}

	function patch()
	{
		global $config;

		$config->set('mod_aucp_notify', NOTIFY_CURRENT_VERSION, true);

		return;
	}

	function fin()
	{
		global $page, $parms;

		$page->output(empty($parms['nopv']) ? 'NO_install_done' : 'NO_install_upgraded');

		return;
	}
}

$parts[] = 'advnot_install';

?>